package com.vdong.trade.trading.service.impl;

import com.vdong.trade.trading.common.exception.ValidateException;
import com.vdong.trade.trading.entity.dto.param.PayConfigParamDTO;
import com.vdong.trade.trading.entity.mo.PayConfigExampleMO;
import com.vdong.trade.trading.entity.mo.PayConfigMO;
import com.vdong.trade.trading.respository.PayConfigMapper;
import com.vdong.trade.trading.service.PayConfigService;
import org.lamb.framework.common.util.CopyUtil;
import org.lamb.framework.common.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class PayConfigServiceImpl implements PayConfigService {

    @Autowired
    private PayConfigMapper payConfigMapper;

    @Override
    public Integer insert(PayConfigParamDTO dto) {
        PayConfigMO payConfigMO = new PayConfigMO();
        CopyUtil.copyObject(dto, payConfigMO);
        payConfigMO.setCreateTime(new Date());
        return payConfigMapper.insertSelective(payConfigMO);
    }

    @Override
    public Integer update(PayConfigParamDTO dto) {
        if (dto.getId() == null || dto.getId() < 1) {
            throw new ValidateException("更新id不能为空!");
        }

        PayConfigMO payConfigMO = new PayConfigMO();
        CopyUtil.copyObject(dto, payConfigMO);
        payConfigMO.setUpdateTime(new Date());
        return payConfigMapper.updateByPrimaryKeySelective(payConfigMO);
    }

    @Override
    public List<PayConfigMO> selectPayConfigList(PayConfigParamDTO dto) {
        PayConfigExampleMO mo = new PayConfigExampleMO();
        if (dto != null) {
            if (!StringUtil.hasBlank(dto.getType())) {
                mo.createCriteria().andTypeEqualTo(dto.getType());
            }
        }
        return payConfigMapper.selectByExampleWithBLOBs(mo);
    }

}
